package cn.xin.system.service.impl;

import cn.xin.base.query.BaseQuery;
import cn.xin.base.util.BussinessException;
import cn.xin.base.util.PageList;
import cn.xin.system.domain.Dictionarytype;
import cn.xin.system.mapper.DictionarytypeMapper;
import cn.xin.system.service.DictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
//@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DictionarytypeServiceImpl implements DictionarytypeService {

    @Autowired
    private DictionarytypeMapper dictionarytypeMapper;

    @Override
    public List<Dictionarytype> findAll() {
        return dictionarytypeMapper.findAll();
    }

    @Override
    public Dictionarytype findById(Long id) {
        return dictionarytypeMapper.findById(id);
    }

    @Override
    public void add(Dictionarytype dictionarytype) {
        dictionarytypeMapper.add(dictionarytype);
    }

    @Override
    public void update(Dictionarytype dictionarytype) {
        dictionarytypeMapper.update(dictionarytype);
    }

    @Override
    public void delete(Long id) {
        if(id == null){
            throw new BussinessException("id为空");
        }
        dictionarytypeMapper.delete(id);
    }

    @Override
    public PageList<Dictionarytype> queryByPage(BaseQuery query) {
        Integer totals = dictionarytypeMapper.queryByCount(query);

        if (totals == 0 || totals == null){
            return new PageList<Dictionarytype>(0,new ArrayList<>());
        }
        List<Dictionarytype> rows = dictionarytypeMapper.queryByPage(query);

        List<Long> ids = rows.stream().map(row->row.getId()).collect(Collectors.toList());

        return new PageList<Dictionarytype>(totals,rows);
    }


    @Override
    public void batchDelete(List<Long> ids) {
        dictionarytypeMapper.batchDelete(ids);
    }


}
